//
//  RegistViewController.m
//  BobNews
//
//  Created by lanou3g on 16/5/5.
//  Copyright © 2016年 YJC. All rights reserved.
//

#import "RegistViewController.h"
#import "NetWorkRequestManager.h"
@interface RegistViewController ()
@property (weak, nonatomic) IBOutlet UITextField *emailTextField;
@property (weak, nonatomic) IBOutlet UIButton *returnBtn;

@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UITextField *unameTextField;

@end

@implementation RegistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"登录";
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"t.jpeg"]];
    self.returnBtn.layer.cornerRadius = 7;
    self.returnBtn.layer.masksToBounds = YES;
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//注册按钮
- (IBAction)registBtnAction:(id)sender {
    [NetWorkRequestManager requestUrl:[NSURL URLWithString:@"http://api2.pianke.me/user/reg"] RequestMethod:POST Params:@{@"email":self.emailTextField.text,@"gender":@"0",@"uname":self.unameTextField.text,@"passwd":self.passwordTextField.text} Result:^(NSData *data, NSURLResponse *response, NSError *error) {
        if (data) {
            NSMutableDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSDictionary *dataDict = jsonDict[@"data"];
            NSString *msg = dataDict[@"msg"];
            msg = msg?msg:@"注册成功";
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
            [alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            }]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self presentViewController:alertC animated:YES completion:nil];
            });
        }
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
